package com.jinlia.show.modules.base.system.service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jinlia.show.modules.base.system.entity.MemberCardBalanceChange;
import com.jinlia.show.modules.base.system.entity.MemberCardScoreChange;
import com.jinlia.show.modules.base.system.mapper.MemberCardScoreChangeMapper;
import com.jinlia.show.modules.base.wxapp.entity.User;
import com.jinlia.show.modules.base.wxapp.service.UserMapperService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;

@Service
@RequiredArgsConstructor
public class MemberCardScoreChangeMapperService extends ServiceImpl<MemberCardScoreChangeMapper, MemberCardScoreChange> {

    final UserMapperService userMapperService;

    public List<MemberCardScoreChange> getScoreChange(Long userId) {
        User byId = userMapperService.getById(userId);
        if (byId.getMemberCardId() == null) {
            return Arrays.asList();
        }
        List<MemberCardScoreChange> list = this.lambdaQuery()
                .eq(MemberCardScoreChange::getMemberCardId, byId.getMemberCardId())
                .orderByDesc(MemberCardScoreChange::getCreateTime)
                .list();
        return list;
    }
}
